﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ChampionFramework.Models;

namespace ChampionFramework.Controllers
{
    public class TaticaController : Controller
    {
        ChampionContextContainer db = new ChampionContextContainer();

        public ActionResult Index()
        {
            return View(db.TaticaSet);
        }


        public ActionResult CreateTatics()
        {
            Tatica tatica = new Tatica();
            tatica.MakeItDefault();
            return View(tatica);
        }

        [HttpPost]
        public ActionResult CreateTaticsPost(Tatica tatica)
        {
            for (int i = 0; i < 11; i++)
            {
                PosicionamentoTatico p = new PosicionamentoTatico();
                p.X = Convert.ToInt32(this.Request.Params[String.Format("{0}X", i)]);
                p.Y = Convert.ToInt32(this.Request.Params[String.Format("{0}Y", i)]);
                tatica.PosicionamentoTatico.Add(p);
            }
            db.TaticaSet.AddObject(tatica);            
            db.SaveChanges();
            return RedirectToAction("index", "Taticas");
        }

        public ActionResult VisualizarTatica(int id)
        {
            return View(db.TaticaSet.Include("PosicionamentoTatico").Single(t => t.Id == id));
        }
    }
}
